/*
 * 功能说明：把document的getElementById函数简化成$()
 * 使用方法：$("EditForm")等价于document.getElementById("EditForm")
 */
var $ = function() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);

		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}
// 页面排序函数
var doSort = function(byName) {
	var f = $("ListForm");
	(f.orderType.value == "asc" || f.orderType.value == "")
			? f.orderType.value = "desc"
			: f.orderType.value = "asc";
	f.orderBy.value = byName;
	f.submit();
};
//弹出窗口
var winOpen = function(strURL,strName,width,height){
    theWindow = window.open (strURL,strName,"width="+width+" height="+height+" scrollbars=yes left="+(1024-width)/2+" top="+(768-height)/2);	
    if (theWindow.opener == null) theWindow.opener = window;
    if (window.focus) theWindow.focus();
}
/**
 * JS工具箱
 */
JsUtil = {};
JsUtil.ajax = function() {
	return {
		/**
		 * 创建XmlHttp对象
		 */
		createAjaxObj : function() {
			var xmlHttp = null;
			try {
				xmlHttp = new XMLHttpRequest;
			} catch (e) {
				try {
					xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
				} catch (e2) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e3) {
						xmlHttp = false;
					}
				}
			}
			return xmlHttp;
		},
		/**
		 * Ajax操作函数
		 * 
		 * @param url --
		 *            服务器端页面地址
		 * @param param --
		 *            参数，类似 'user=123&id=100'
		 * @param mode --
		 *            请求服务器端的方法,GET和POST两种，默认是GET
		 * @param response --
		 *            回调函数
		 */
		ajaxRequest : function(url, param, mode, callback) {
			// create ajax object
			var xmlHttp = this.createAjaxObj();
			var data_back = function() {
				if (xmlHttp.readyState == 4) {
					if (xmlHttp.status == 200) {
						var text = xmlHttp.responseText;
						var xml = xmlHttp.responseXML;
						callback(text, xml);
					} else {
						alert("Ajax请求失败,请检测您的网络是否正常或请求条件造成后端出错.")
					}
				}
			}
			// 清出缓存
			if (!param)
				url += "&time=" + new Date().getTime();
			else
				param += "&time=" + new Date().getTime();
			if (mode == "POST") {
				xmlHttp.open(mode, url, true);
				xmlHttp.setRequestHeader("Content-Type",
						"application/x-www-form-urlencoded");
				xmlHttp.onreadystatechange = data_back;
				xmlHttp.send(param);
			} else if (mode == "GET" || mode == "" || mode == null) {
				xmlHttp.open("GET", url + (param || ''), true);
				xmlHttp.onreadystatechange = data_back;
				xmlHttp.send(null);
			}
		}
	};
}();
// 选择数据字典对话框
JsUtil.choiceDictionary = function(sn, title, callback) {
	ModalDialog.show("150px", "150px", null, function(result) {
				if (!result)
					callback({
								id : "",
								name : ""
							});
				else {
					callback(result);
				}
			}, title);
	EasyAjaxUtil.daymicLoadUrl("ajax.do?cmd=getDictionaryBySn&sn="
					+ sn, function(req) {
				var ret = eval(req.responseText);
				ret.pop();//把最后一个元素移出掉(null)
				var list = ret;
				ModalDialog.DictionaryQueryResult(list);
			});
	ModalDialog.DictionaryQueryResult = function(list) {
	$("modalDialogSelectList").options.length = 0;
	ModalDialog.dialogData = list;
	if (list.length) {
		for (var i = 0; i < list.length; i++) {
			$("modalDialogSelectList").options[i] = new Option(list[i].name,list[i].id);
		}
	}
	}
};
//着重显示鼠标移动到当前行
JsUtil.displace = function(_this,b){
	if(b){
		_this.style["backgroundColor"] = "#CBFD8E";
		_this.style["fontWeight"] = 800;
		_this.style["cursor"] = "pointer";
	}else{ 
		JsUtil.interleaved(((_this.id).split('_'))[1]);
		_this.style.fontWeight = "normal";
	};
}
//隔行变色
JsUtil.interleaved = function(p){
	for(var i=1; i<=p; i++){
		var obj = $("sn_"+i);
		//证明是奇数行
		if(obj && (i%2==1)){
			obj.style.background = "#fff";
		}else if(obj){
			obj.style.background = "#EBFED3";
		}
	}
}